package com.wenli.lt.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.wenli.lt.entity.Collections;
import com.wenli.lt.mapper.CollectionsMapper;
import com.wenli.lt.service.ICollectionsService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.UUID;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author lt
 * @since 2021-03-23
 */
@Service
public class CollectionsServiceImpl extends ServiceImpl<CollectionsMapper, Collections> implements ICollectionsService {
    @Autowired
    CollectionsMapper collectionsMapper;

    @Override
    public Boolean addCollections(Collections collections) {
        collections.setCollectionsId(UUID.randomUUID().toString().replace("-",""));
        return 1 == collectionsMapper.insert(collections);
    }

    @Override
    public Boolean deleteCollections(String goodsId,String collectionsStuNum) {
        QueryWrapper<Collections> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("goodsId",goodsId);
        queryWrapper.eq("collectionsStuNum",collectionsStuNum);
        Collections collections = collectionsMapper.selectOne(queryWrapper);
        return 1 == collectionsMapper.deleteById(collections.getCollectionsId());
    }

    @Override
    public List<Map> myCollections(String studentNumber) {

        return collectionsMapper.myCollections(studentNumber);
    }
}
